﻿using TopVisionLog;

namespace TopVisionVideoStream
{
    class AccountManager
    {
        public static string Account
        {
            get { return Configuration.Account; }
        }

        public static string Password
        {
            get { return Configuration.Password; }
        }

        public static bool IsLoged
        {
            get { return Configuration.IsLoged; }
        }

        public static event UnRegistEventHandler UnRegistEvent
        {
            add { Model_Login.UnRegistEvent += value; }
            remove { Model_Login.UnRegistEvent -= value; }
        }


        public static void Init()
        {
            Model_Login.RegistLoginEvent();
            Model_Logout.RegistLogoutEvent();
        }


        #region Login

        public static bool Login(string account, string password, LoginEvent result)
        {
            TVLog.WriteLine(">>开始登录:" + account);

            return Model_Login.Call(account, password, result);
        }

        #endregion


        #region Logout

        public static bool Logout(LogoutEvent result)
        {
            TVLog.WriteLine(">>开始登出");

            return Model_Logout.Call(result);
        }

        #endregion


        public static void Dispose()
        {
            if (IsLoged)
                Model_Logout.Call(null);

            Model_Login.Dispose();

            Model_Logout.Dispose();
        }
    }
}
